//
//  HDSelectItemCell.m
//  CreditGroup
//
//  Created by Mirko on 2017/1/19.
//  Copyright © 2017年 haodai. All rights reserved.
//

#import "HDSelectItemCell.h"
#import <MCPublicModule/MCPMCommonHeader.h>

@interface HDSelectItemCell ()

@property (weak, nonatomic) IBOutlet UILabel *month;
@property (weak, nonatomic) IBOutlet UIView *gbView;
@property (weak, nonatomic) IBOutlet UIView *selectBgView;
@property (weak, nonatomic) IBOutlet UIView *tipsView;
@property (weak, nonatomic) IBOutlet UIView *tipsViewRight;
@property (weak, nonatomic) IBOutlet UILabel *flage;
@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *height;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topGap;


@end

@implementation HDSelectItemCell

-(void) awakeFromNib
{
    [super awakeFromNib];
    self.layer.masksToBounds = NO;
    self.contentView.layer.masksToBounds = NO;
    self.tipsView.layer.masksToBounds = NO;
    self.tipsViewRight.layer.masksToBounds = NO;
    self.selectBgView.layer.masksToBounds = NO;
    self.selectBgView.layer.masksToBounds = NO;
    self.tipsView.hidden = YES;
    self.tipsViewRight.hidden = YES;
    self.height.constant = 0;
    self.topGap.constant = 0;
}


-(void) setCellData:(id) cellData
{
    if (![cellData isKindOfClass:[HDMonthControlModle class]]) {
        NSLog(@"cell data is err");
        return;
    }
    
    
    self.controlModle = cellData;
    NSLog(@"CellData row:%ld section:%ld", self.controlModle.indexPath.row, self.controlModle.indexPath.section);
    self.month.text = [NSString stringWithFormat:@"%@月", self.controlModle.month];
    if (self.controlModle.status == kStatusUnavail) {
        self.userInteractionEnabled = NO;
        self.month.textColor = [UIColor colorWithRed:204.f/255 green:204.f/255 blue:204.f/255 alpha:1];
        self.selectBgView.backgroundColor = [UIColor whiteColor];
    }
    else if (self.controlModle.status == kStatusDefault)
    {
//        self.selected = NO;
        self.userInteractionEnabled = YES;
        self.selectBgView.backgroundColor = [UIColor colorWithRed:134/255.0 green:180/255.0 blue:255/255.0 alpha:1];
        self.month.textColor = [UIColor colorWithRed:51.f/255 green:51.f/255 blue:51.f/255 alpha:1];
    }
    else
    {
//        self.selected = YES;
        self.userInteractionEnabled = YES;
        self.selectBgView.backgroundColor = [UIColor colorWithRed:134/255.0 green:180/255.0 blue:255/255.0 alpha:1];
        self.month.textColor = [UIColor whiteColor];
    }
    
    [self showStatusFlag];
}

-(void) showTips:(NSIndexPath*) indexPath
{
    NSLog(@"row : %ld", indexPath.row);
    NSInteger temp = (indexPath.row + 1) % 4;
    if (temp == 1 || temp == 2) {
        self.tipsView.hidden = YES;
        self.tipsViewRight.hidden = NO;
    }
    else
    {
        self.tipsView.hidden = NO;
        self.tipsViewRight.hidden = YES;
    }
}

-(void) showStatusFlag
{
    NSLog(@"CellData row:%ld section:%ld", self.controlModle.indexPath.row, self.controlModle.indexPath.section);
    if (self.controlModle.flag == kFlagStart) {
        self.height.constant = 21;
        self.topGap.constant = 10;
        self.flage.text = @"开始";
    }
    else if (self.controlModle.flag == kFlagEnd)
    {
        self.height.constant = 21;
        self.topGap.constant = 10;
        self.flage.text = @"结束";
    }
    else
    {
        self.height.constant = 0;
        self.topGap.constant = 0;
        self.flage.text = nil;
    }
}

-(void) hiddenTips
{
    self.tipsView.hidden = YES;
    self.tipsViewRight.hidden = YES;
}

//-(BOOL) isSelected
//{
//    BOOL select = [super isSelected];
//    if (select) {
//        self.month.textColor = [UIColor whiteColor];
//    }
//    else
//    {
//        self.month.textColor = [UIColor colorWithRed:51.f/255 green:51.f/255 blue:51.f/255 alpha:1];
//    }
//    return select;
//}

-(BOOL) isHighlighted
{
    return [super isHighlighted];
}

@end
